package org.rufolfheszele.andpixelbyandpixel.configuration;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This class holds the address of the proxy from the configuration data
 *
 * @author Rudolf Heszele heszele@gmail.com
 * @version 2.0
 * @since 2012-05-19
 */
public class ProxyAddress
{
		/**
		 * The only constructor takes the XML node and reads every data into its data members
		 *
		 * @param node The XML node containing the network configuration
		 */
		public ProxyAddress(Node node)
		{
			NodeList children = node.getChildNodes();

			mNode = node;
			for(int i = 0; i < children.getLength(); ++i)
			{
				Node childNode = children.item(i);
				
				if(true == childNode.getNodeName().equals("host"))
					mHost = childNode.getChildNodes().item(0).getNodeValue();
				if(true == childNode.getNodeName().equals("port"))
					mPort = Integer.parseInt(childNode.getChildNodes().item(0).getNodeValue());
			}
		}
		
		public String getHost()
		{
			return mHost;
		}
		
		public void setHost(String host)
		{
			String nodeContent;

			mHost = host;
			nodeContent = mHost;
			Configuration.updateNodeContent(mNode, "host", nodeContent, null);
		}
		
		public int getPort()
		{
			return mPort;
		}
		
		public void setPort(int port)
		{
			String nodeContent;

			mPort = port;
			nodeContent = Integer.toString(port);
			Configuration.updateNodeContent(mNode, "port", nodeContent, null);
		}

		private String mHost	= null;
		private int mPort		= -1;
		private Node mNode		= null;
};
